package com.hm.PushCaseService.service.push.qycg.delete;

import com.hm.PushCaseService.constant.ReqUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;


@Service
public class DeleteCaseService implements IDeleteCase {
    private static final Logger logger = LoggerFactory.getLogger(DeleteCaseService.class);

    @Qualifier("OkHttpClient")
    public OkHttpClient okHttpClient;

    public DeleteCaseService(OkHttpClient okHttpClient) {
        this.okHttpClient = okHttpClient;
    }

    @Override
    public void delete(String eventCode, String cookie) {
        String deleteUrl = ReqUrl.DeleteUrl + "?eventCode=" + eventCode;
        Request request = new Request.Builder()//
                .url(deleteUrl)//
                .addHeader("Content-Type", "application/json; charset=UTF-8")//添加请求类型
                .addHeader("Cookie", cookie)//
                .build();//
        try (Response response = okHttpClient.newCall(request).execute()) {
            ResponseBody resBody = response.body();
            if (resBody != null) {
                logger.error("ResponseBody:" + resBody.string());
            } else {
                logger.error("删除案件接口resBody为null！！ ");
            }
        } catch (Exception e) {
            logger.error("删除异常：Exception: " + e.getMessage());
        }
    }

}
